package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 石小俊
 * 绘制添加员工的页面
 * 该页面中不涉及任何后端数据,只是单纯的绘制页面
 */
@WebServlet("/showAddEmp")
public class ShowAddEmpServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 在返回响应的时候,其数据可能存在乱码
        // 因此,可以通过响应对象设置响应数据的格式
        // setContentType()方法用于设置响应数据的格式
        // 常用值:text/html;charset=utf-8表示响应数据是一个html文本,其字符集为utf-8
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.println(" <!DOCTYPE html> ");
        out.println(" <html lang=\"en\"> ");
        out.println(" <head> ");
        out.println("     <meta charset=\"UTF-8\"> ");
        out.println("     <title>添加员工</title> ");
        out.println(" </head> ");
        out.println(" <body> ");
        out.println(" <h1>添加员工信息</h1> ");
        out.println(" <a href=\"\">返回员工列表</a> ");
        out.println(" <hr> ");
        out.println(" <form action=\"addEmp\" method=\"post\"> ");
        out.println("     姓名:<input type=\"text\" name=\"name\"><br> ");
        out.println("     工资:<input type=\"text\" name=\"salary\"><br> ");
        out.println("     性别:<input type=\"radio\" name=\"gender\" value=\"man\">男 ");
        out.println("     <input type=\"radio\" name=\"gender\" value=\"woman\">女<br> ");
        out.println("     学历: ");
        out.println("     <select name=\"edu\"> ");
        out.println("         <option value=\"-1\">请选择</option> ");
        out.println("         <option value=\"1\">大专</option> ");
        out.println("         <option value=\"2\">本科</option> ");
        out.println("         <option value=\"3\">研究生</option> ");
        out.println("         <option value=\"4\">博士生</option> ");
        out.println("     </select><br> ");
        out.println("     兴趣: ");
        out.println("     <input type=\"checkbox\" name=\"hobbies\" value=\"eat\">吃饭 ");
        out.println("     <input type=\"checkbox\" name=\"hobbies\" value=\"sleep\">睡觉 ");
        out.println("     <input type=\"checkbox\" name=\"hobbies\" value=\"beat\">打豆豆<br> ");
        out.println("     <input type=\"submit\" value=\"添加\"> ");
        out.println(" </form> ");
        out.println(" </body> ");
        out.println(" </html> ");
    }
}
